with v8.Class_Template, v8.Class_Object, v8.Class_Accessor_Info, v8.Class_Arguments;
with v8.Class_Value, v8.Class_String, v8.Class_Integer, v8.Class_Boolean;
with v8.Class_Array;
package v8.Class_Object_Template is
   type Object_Template (<>) is new v8.Class_Template.Template with private;
   type Pointer is access all Object_Template;
   -- An Object_Template is used to create objects at runtime.
   --
   -- Properties added to an ObjectTemplate are added to each object
   -- created from the ObjectTemplate.

   -- Named_Property[Getter|Setter] are used as interceptors on object.
   -- See Object_Template::Set_Named_Property_Handler.
   type Named_Property_Getter is access function
     (property      : v8.Class_String.Pointer;
      accessor_info : v8.Class_Accessor_Info.Accessor_Info
     ) return v8.Class_Value.Pointer;
   type Named_Property_Setter is access function
     (property      : v8.Class_String.Pointer;
      value         : v8.Class_Value.Pointer;
      accessor_info : v8.Class_Accessor_Info.Accessor_Info
     ) return v8.Class_Value.Pointer;

   type Named_Property_Query is access function
     (property      : v8.Class_String.Pointer; -- Local<String>
      accessor_info : v8.Class_Accessor_Info.Accessor_Info
     ) return v8.Class_Integer.Pointer;
   -- return Handle<Integer>
   -- Returns a non-empty handle if the interceptor intercepts the request.
   -- The result is an integer encoding property attributes (like v8::None,
   -- v8::DontEnum, etc.)

   type Named_Property_Deleter is access function
     (property          : v8.Class_String.Pointer; -- Local<String>
      accessor_info     : v8.Class_Accessor_Info.Accessor_Info
     ) return v8.Class_Boolean.Pointer;
   -- return Handle<Boolean>
   -- Returns a non-empty handle if the deleter intercepts the request.
   -- The return value is true if the property could be deleted and false
   -- otherwise.

   type Named_Property_Enumerator is access function
     (accessor_info : v8.Class_Accessor_Info.Accessor_Info
     ) return v8.Class_Array.Pointer;
   -- return Handle<Array>
   -- Returns an array containing the names of the properties the named
   -- property getter intercepts.

   type Indexed_Property_Getter is access function
     (index           : uint32_t;
      aaccessor_info  : v8.Class_Accessor_Info.Accessor_Info
     ) return v8.Class_Value.Pointer;
   -- Returns the value of the property if the getter intercepts the
   -- request.  Otherwise, returns an empty handle.

   type Indexed_Property_Setter is access function
     (index         : uint32_t;
      value         : v8.Class_Value.Pointer; -- Local<Value>
      accessor_info : v8.Class_Accessor_Info.Accessor_Info
     ) return v8.Class_Value.Pointer;
   -- return Handle<Value>
   -- Returns the value if the setter intercepts the request.
   -- Otherwise, returns an empty handle.

   type Indexed_Property_Query is access function
     (index           : uint32_t;
      aaccessor_info  : v8.Class_Accessor_Info.Accessor_Info
     ) return v8.Class_Boolean.Pointer;
   -- return Handle<Boolean>
   -- Returns a non-empty handle if the interceptor intercepts the request.
   -- The result is an integer encoding property attributes.

   type Indexed_Property_Deleter is access function
     (index          : uint32_t;
      accessor_info  : v8.Class_Accessor_Info.Accessor_Info
     ) return v8.Class_Boolean.Pointer;
   -- return Handle<Boolean>
   -- Returns a non-empty handle if the deleter intercepts the request.
   -- The return value is true if the property could be deleted and false
   -- otherwise.

   type Indexed_Property_Enumerator is access function
     (accessor_info :  v8.Class_Accessor_Info.Accessor_Info
     ) return v8.Class_Array.Pointer;
   -- return Handle<Array>
   -- Returns an array containing the indices of the properties the
   -- indexed property getter intercepts.

   type Named_Security_Callback is access function
     (host         : v8.CLass_Object.Pointer; -- Local<Object>
      key          : v8.Class_Value.Pointer; -- Local<Value>
      a_type       : Access_Type.Enum;
      data         : v8.Class_Value.Pointer -- Local<Value>
     ) return bool;
   -- Returns true if cross-context access should be allowed to the named
   -- property with the given key on the host object.

   type Indexed_Security_Callback is access function
     (host          : v8.Class_Object.Pointer; -- Local<Object>
      index         : uint32_t;
      a_type        : Access_Type.Enum;
      data          : v8.Class_Value.Pointer -- Local<Value>
     ) return bool;
   -- Returns true if cross-context access should be allowed to the indexed
   -- property with the given index on the host object.




   function Create return Pointer;
   -- return Local<ObjectTemplate>
   -- Creates an ObjectTemplate.

   function New_Instance
     (this : in out Object_Template
     ) return v8.Class_Object.Pointer;
   -- return Local<Object>
   -- Creates a new instance of this template.

   procedure Set_Accessor
     (this      : in out Object_Template;
      name      : v8.Class_String.Pointer;
      getter    : v8.Class_Accessor_Info.Accessor_Getter;
      setter    : v8.Class_Accessor_Info.Accessor_Setter := null;
      data      : v8.Class_Value.Pointer := null;
      settings  : Access_Control.Enum := Access_Control.DEFAULT;
      attribute : Property_Attribute.Enum := Property_Attribute.None);
   -- Sets an accessor on the object template.
   --
   -- Whenever the property with the given name is accessed on objects
   -- created from this Object_Template the getter and setter callbacks
   -- are called instead of getting and setting the property directly
   -- on the JavaScript object.
   --
   -- \param name The name of the property for which an accessor is added.
   -- \param getter The callback to invoke when getting the property.
   -- \param setter The callback to invoke when setting the property.
   -- \param data A piece of data that will be passed to the getter and setter
   --   callbacks whenever they are invoked.
   -- \param settings Access control settings for the accessor. This is a bit
   --   field consisting of one of more of
   --   DEFAULT = 0, ALL_CAN_READ = 1, or ALL_CAN_WRITE = 2.
   --   The default is to not allow cross-context access.
   --   ALL_CAN_READ means that all cross-context reads are allowed.
   --   ALL_CAN_WRITE means that all cross-context writes are allowed.
   --   The combination ALL_CAN_READ | ALL_CAN_WRITE can be used to allow all
   --   cross-context access.
   -- \param attribute The attributes of the property for which an accessor
   --   is added.

   procedure Set_Named_Property_Handler
     (this       : in out Object_Template;
      getter     : Named_Property_Getter;
      setter     : Named_Property_Setter := null;
      query      : Named_Property_Query := null;
      deleter    : Named_Property_Deleter := null;
      enumerator : Named_Property_Enumerator := null;
      data       : v8.Class_Value.Pointer := null);
   -- Sets a named property handler on the object template.
   --
   -- Whenever a named property is accessed on objects created from
   -- this object template, the provided callback is invoked instead of
   -- accessing the property directly on the JavaScript object.
   --
   -- \param getter The callback to invoke when getting a property.
   -- \param setter The callback to invoke when setting a property.
   -- \param query The callback to invoke to check if a property is present,
   --   and if present, get its attributes.
   -- \param deleter The callback to invoke when deleting a property.
   -- \param enumerator The callback to invoke to enumerate all the named
   --   properties of an object.
   -- \param data A piece of data that will be passed to the callbacks
   --   whenever they are invoked.

   procedure Set_Indexed_Property_Handler
     (this       : in out Object_Template;
      getter     : Indexed_Property_Getter;
      setter     : Indexed_Property_Setter := null;
      query      : Indexed_Property_Query := null;
      deleter    : Indexed_Property_Deleter := null;
      enumerator : Indexed_Property_Enumerator := null;
      data       : v8.Class_Value.Pointer := null);
   -- Sets an indexed property handler on the object template.
   --
   -- Whenever an indexed property is accessed on objects created from
   -- this object template, the provided callback is invoked instead of
   -- accessing the property directly on the JavaScript object.
   --
   -- \param getter The callback to invoke when getting a property.
   -- \param setter The callback to invoke when setting a property.
   -- \param query The callback to invoke to check if an object has a property.
   -- \param deleter The callback to invoke when deleting a property.
   -- \param enumerator The callback to invoke to enumerate all the indexed
   --   properties of an object.
   -- \param data A piece of data that will be passed to the callbacks
   --   whenever they are invoked.

   procedure Set_Call_As_Function_Handler
     (this     : in out Object_Template;
      callback : v8.Class_Arguments.Invocation_Callback;
      data     : v8.Class_Value.Pointer := null);
   -- Sets the callback to be used when calling instances created from
   -- this template as a function.  If no callback is set, instances
   -- behave like normal JavaScript objects that cannot be called as a
   -- function.

   procedure Mark_As_Undetectable (this : in out Object_Template);
   -- Mark object instances of the template as undetectable.
   --
   -- In many ways, undetectable objects behave as though they are not
   -- there.  They behave like 'undefined' in conditionals and when
   -- printed.  However, properties can be accessed and called as on
   -- normal objects.

   procedure Set_Access_Check_Callbacks
     (this                 : in out Object_Template;
      named_handler        : Named_Security_Callback;
      indexed_handler      : Indexed_Security_Callback;
      data                 : v8.Class_Value.Pointer := null;
      turned_on_by_default : bool := -True);
   -- Sets access check callbacks on the object template.
   --
   -- When accessing properties on instances of this object template,
   -- the access check callback will be called to determine whether or
   -- not to allow cross-context access to the properties.
   -- The last parameter specifies whether access checks are turned
   -- on by default on instances. If access checks are off by default,
   -- they can be turned on on individual instances by calling
   -- Object::Turn_On_Access_Check().

   function Internal_Field_Count (this : Object_Template) return int;
   -- Gets the number of internal fields for objects generated from
   -- this template.

   procedure Set_Internal_Field_Count
     (this  : in out Object_Template;
      value : int);
   -- Sets the number of internal fields for objects generated from
   -- this template.

private
   type Object_Template is new v8.Class_Template.Template with null record;

   pragma Convention (CPP, Named_Property_Getter);
   pragma Convention (CPP, Named_Property_Setter);
   pragma Convention (CPP, Named_Property_Query);
   pragma Convention (CPP, Named_Property_Deleter);
   pragma Convention (CPP, Named_Property_Enumerator);
   pragma Convention (CPP, Indexed_Property_Getter);
   pragma Convention (CPP, Indexed_Property_Setter);
   pragma Convention (CPP, Indexed_Property_Query);
   pragma Convention (CPP, Indexed_Property_Deleter);
   pragma Convention (CPP, Indexed_Property_Enumerator);
   pragma Convention (CPP, Named_Security_Callback);
   pragma Convention (CPP, Indexed_Security_Callback);

   pragma Import (CPP, Create, "_ZN2v814ObjectTemplate3NewEv");
   pragma Import (CPP, New_Instance, "_ZN2v814ObjectTemplate11NewInstanceEv");
   pragma Import (CPP, Set_Accessor, "_ZN2v814ObjectTemplate11SetAccessorENS_6HandleINS_6StringEEEPFNS1_INS_5ValueEEENS_5LocalIS2_EERKNS_12AccessorInfoEEPFvS7_NS6_IS4_EESA_ES5_NS_13AccessControlENS_17PropertyAttributeE");
   pragma Import (CPP, Set_Named_Property_Handler, "_ZN2v814ObjectTemplate23SetNamedPropertyHandlerEPFNS_6HandleINS_5ValueEEENS_5LocalINS_6StringEEERKNS_12AccessorInfoEEPFS3_S6_NS4_IS2_EES9_EPFNS1_INS_7IntegerEEES6_S9_EPFNS1_INS_7BooleanEEES6_S9_EPFNS1_INS_5ArrayEEES9_ES3_");
   pragma Import (CPP, Set_Indexed_Property_Handler, "_ZN2v814ObjectTemplate25SetIndexedPropertyHandlerEPFNS_6HandleINS_5ValueEEEjRKNS_12AccessorInfoEEPFS3_jNS_5LocalIS2_EES6_EPFNS1_INS_7IntegerEEEjS6_EPFNS1_INS_7BooleanEEEjS6_EPFNS1_INS_5ArrayEEES6_ES3_");
   pragma Import (CPP, Set_Call_As_Function_Handler, "_ZN2v814ObjectTemplate24SetCallAsFunctionHandlerEPFNS_6HandleINS_5ValueEEERKNS_9ArgumentsEES3_");
   pragma Import (CPP, Mark_As_Undetectable, "_ZN2v814ObjectTemplate18MarkAsUndetectableEv");
   pragma Import (CPP, Set_Access_Check_Callbacks, "_ZN2v814ObjectTemplate23SetAccessCheckCallbacksEPFbNS_5LocalINS_6ObjectEEENS1_INS_5ValueEEENS_10AccessTypeES5_EPFbS3_jS6_S5_ENS_6HandleIS4_EEb");
   pragma Import (CPP, Internal_Field_Count, "_ZN2v814ObjectTemplate18InternalFieldCountEv");
   pragma Import (CPP, Set_Internal_Field_Count, "_ZN2v814ObjectTemplate21SetInternalFieldCountEi");
end v8.Class_Object_Template;
